﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Infrastructure;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Prism.Regions;
using System.Threading;
using System.IO;
using DBDataAccessLib;

namespace Services
{
    public class ServicesModule : ModuleBase
    {
        public ServicesModule(IEventAggregator eventAggregator, IUnityContainer container, IRegionManager regionManager)
            : base(eventAggregator, container, regionManager)
        {

        }
        protected override void RegisterViewsAndServices()
        {
            InitialWCNOMapping();
            string serverUri = Helper.GetConfigurationValue("ImageServerURI");
            string wcno = Helper.GetConfigurationValue("WCNO");
            string stationName = Helper.GetConfigurationValue("StationName");
            if (Helper.GetConfigurationValue("Client") == "Office")
            {
                InitialSebangoMapping();
            }
            else
            {
                if (Directory.Exists(serverUri + wcno + "\\" + stationName))
                {
                    if (Directory.Exists(Helper.BaseUri + wcno + "\\" + stationName))
                        Directory.Delete(Helper.BaseUri + wcno + "\\" + stationName, true);
                    Directory.CreateDirectory(Helper.BaseUri + wcno + "\\" + stationName);
                    foreach (var item in Directory.GetFiles(serverUri + wcno + "\\" + stationName))
                    {
                        FileInfo info = new FileInfo(item);
                        File.Copy(item, Helper.BaseUri + wcno + "\\" + stationName + "\\" + info.Name, true);
                    }
                }
            }
        }

        private void InitialSebangoMapping()
        {
            SebangoMapping.Sebangos = GSVXDataAccess.GetSebangoMappings();
        }

        private void InitialWCNOMapping()
        {
            WCNOMapping.WCNOS = LineNameDataAccess.GetLinesByJIBU("70");
        }
    }
}
